package com.chixing.ih.module.programmer.mapper.provider;

import com.chixing.ih.module.programmer.pojo.Evaluate;
import com.chixing.ih.util.EmptyUtil;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘岩
 * Date: 2020-09-30
 * Time: 8:47
 *
 * @version 1.0
 */
public class EvaluateMapperProvider {


    public String insertOne() {
        return new SQL() {{
            INSERT_INTO("tbl_evaluate");
            VALUES("user_evaluate_id", "#{userEvaluateId}");
            VALUES("user_evaluated_id", "#{userEvaluatedId}");
            VALUES("skill_score", "#{skillScore}");
            VALUES("attitude_score", "#{attitudeScore}");
            VALUES("punctuality_score", "#{punctualityScore}");
            VALUES("evaluated_desc", "#{evaluatedDesc}");
            VALUES("create_time", "#{createTime}");
        }}.toString();
    }


    public String deleteOneById() {
        return new SQL() {{
            UPDATE("tbl_evaluate");
            SET("is_deleted=1");
            WHERE("id=#{id}");
        }}.toString();
    }


    public String updateOne(Evaluate evaluate) {
        return new SQL() {{
            UPDATE("tbl_evaluate");
            if (!EmptyUtil.isEmpty(evaluate.getSkillScore())) {
                SET("skill_score=#{skillScore}");
            }
            if (!EmptyUtil.isEmpty(evaluate.getAttitudeScore())) {
                SET("attitude_score=#{attitudeScore}");
            }
            if (!EmptyUtil.isEmpty(evaluate.getPunctualityScore())) {
                SET("punctuality_score=#{punctualityScore}");
            }
            if (!EmptyUtil.isEmpty(evaluate.getEvaluatedDesc())) {
                SET("evaluated_desc=#{evaluatedDesc}");
            }
            WHERE("id=#{id}");

        }}.toString();


    }

    public String listAll() {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_evaluate");
            WHERE("is_deleted=0 AND user_evaluated_id=#{userEvaluatedId}");
        }}.toString();
    }

    public String getStarRating() {
        return new SQL() {{
            SELECT("truncate(sum(attitude_score+punctuality_score+skill_score)/count(1)/3,1)");
            FROM("tbl_evaluate");
            WHERE("is_deleted=0 AND user_evaluated_id=#{userEvaluatedId}");
        }}.toString();
    }

}
